<?php
include_once dirname(__FILE__)."/../../model/config.php";
		$_ascel_users=new ascel_users();
if(isset($_POST["operation"])){
if($_POST["operation"]=="INSERT"){
		if(isset($_POST["id"])){$_ascel_users->set_id($_POST["id"]);}
		if(isset($_POST["login"])){$_ascel_users->set_login($_POST["login"]);}
		if(isset($_POST["pwd"])){$_ascel_users->set_pwd($_POST["pwd"]);}
		if(isset($_POST["nom"])){$_ascel_users->set_nom($_POST["nom"]);}
		if(isset($_POST["prenom"])){$_ascel_users->set_prenom($_POST["prenom"]);}
		if(isset($_POST["profil"])){$_ascel_users->set_profil($_POST["profil"]);}
		if(isset($_POST["actif"])){$_ascel_users->set_actif($_POST["actif"]);}
		if(isset($_POST["date_der_acces"])){$_ascel_users->set_date_der_acces($_POST["date_der_acces"]);}
		if(isset($_POST["cin"])){$_ascel_users->set_cin($_POST["cin"]);}
		if(isset($_POST["tel"])){$_ascel_users->set_tel($_POST["tel"]);}
		if(isset($_POST["grade"])){$_ascel_users->set_grade($_POST["grade"]);}
		if(isset($_POST["specialite"])){$_ascel_users->set_specialite($_POST["specialite"]);}
		if(isset($_POST["mail"])){$_ascel_users->set_mail($_POST["mail"]);}
		$res=$_ascel_users->INSERT(); 

	   if($res!="success"){
		echo json_encode(array('success' => 'false','result' => "$res" ));
	  }else{
	  	echo json_encode(array('success' => 'true','result' => "$res" ));
	  	
	  }
}
elseif($_POST["operation"]=="DELETE"){
		if(isset($_POST["id"])){
		$_ascel_users->set_id($_POST["id"]);
		$res=$_ascel_users->DELETE(); 

	   if($res!="success"){
		echo json_encode(array('success' => 'false','result' => "$res" ));
	  }else{
	  	echo json_encode(array('success' => 'true','result' => "$res" ));
	  	
	  }
		}
}
elseif($_POST["operation"]=="UPDATE"){
		if(isset($_POST["id"])){$_ascel_users->set_id($_POST["id"]);}
		if(isset($_POST["login"])){$_ascel_users->set_login($_POST["login"]);}
		if(isset($_POST["pwd"])){$_ascel_users->set_pwd($_POST["pwd"]);}
		if(isset($_POST["nom"])){$_ascel_users->set_nom($_POST["nom"]);}
		if(isset($_POST["prenom"])){$_ascel_users->set_prenom($_POST["prenom"]);}
		if(isset($_POST["profil"])){$_ascel_users->set_profil($_POST["profil"]);}
		if(isset($_POST["actif"])){$_ascel_users->set_actif($_POST["actif"]);}
		if(isset($_POST["date_der_acces"])){$_ascel_users->set_date_der_acces($_POST["date_der_acces"]);}
		if(isset($_POST["cin"])){$_ascel_users->set_cin($_POST["cin"]);}
		if(isset($_POST["tel"])){$_ascel_users->set_tel($_POST["tel"]);}
		if(isset($_POST["grade"])){$_ascel_users->set_grade($_POST["grade"]);}
		if(isset($_POST["specialite"])){$_ascel_users->set_specialite($_POST["specialite"]);}
		if(isset($_POST["mail"])){$_ascel_users->set_mail($_POST["mail"]);}
		$res=$_ascel_users->UPDATE(); 

	   if($res!="success"){
		echo json_encode(array('success' => 'false','result' => "$res" ));
	  }else{
	  	echo json_encode(array('success' => 'true','result' => "$res" ));
	  	
	  }
}

}
else{
	$constraint='';$limit=0;$start=0;$pagination='';
	if(isset($_POST["id"]) && !empty($_POST["id"])){
		$constraint.=" AND id='".$_POST["id"]."'";
	}

	if(isset($_POST["login"]) && !empty($_POST["login"])){
		$constraint.=" AND login='".$_POST["login"]."'";
	}

	if(isset($_POST["pwd"]) && !empty($_POST["pwd"])){
		$constraint.=" AND pwd='".$_POST["pwd"]."'";
	}

	if(isset($_POST["nom"]) && !empty($_POST["nom"])){
		$constraint.=" AND nom='".$_POST["nom"]."'";
	}

	if(isset($_POST["prenom"]) && !empty($_POST["prenom"])){
		$constraint.=" AND prenom='".$_POST["prenom"]."'";
	}

	if(isset($_POST["profil"]) && !empty($_POST["profil"])){
		$constraint.=" AND profil='".$_POST["profil"]."'";
	}

	if(isset($_POST["actif"]) && !empty($_POST["actif"])){
		$constraint.=" AND actif='".$_POST["actif"]."'";
	}

	if(isset($_POST["date_der_acces"]) && !empty($_POST["date_der_acces"])){
		$constraint.=" AND date_der_acces='".$_POST["date_der_acces"]."'";
	}

	if(isset($_POST["cin"]) && !empty($_POST["cin"])){
		$constraint.=" AND cin='".$_POST["cin"]."'";
	}

	if(isset($_POST["tel"]) && !empty($_POST["tel"])){
		$constraint.=" AND tel='".$_POST["tel"]."'";
	}

	if(isset($_POST["grade"]) && !empty($_POST["grade"])){
		$constraint.=" AND grade='".$_POST["grade"]."'";
	}

	if(isset($_POST["specialite"]) && !empty($_POST["specialite"])){
		$constraint.=" AND specialite='".$_POST["specialite"]."'";
	}

	if(isset($_POST["mail"]) && !empty($_POST["mail"])){
		$constraint.=" AND mail='".$_POST["mail"]."'";
	}

	if(isset($_POST['limit'])){$limit=$_POST['limit'];}
	if(isset($_POST['start'])){$start=$_POST['start'];}
	if($limit>0){
		$pagination.=" LIMIT  $start,$limit"; 
}
		$res=$_ascel_users->SELECT($constraint,$pagination); 

		 $data=array();
		  while($row=$_ascel_users->fetch_object()){
		  	$data[]=$row;
	  	  }
  	 	 
		
	   if($res!="success"){
		echo json_encode(array('success' => 'false','result' => "$res" ));
	  }else{
	  	echo json_encode(array('totalcount' => count($data),'result' => $data ));
	  	
	  }}
?>